<?php

/**
 * Usuario form.
 *
 * @package    ehockey
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class UsuarioForm extends BaseUsuarioForm
{
	public function configure()
	{
  		$this->defaults['cambiar_password'] = 'Cambiar';
		$this->widgetSchema['password'] = new sfWidgetFormInputPassword();
		$this->widgetSchema['confirmar_password'] = new sfWidgetFormInputPassword();
		$this->widgetSchema->moveField('confirmar_password', sfWidgetFormSchema::AFTER, 'password');
		
		$this->validatorSchema['email'] = new sfValidatorAnd(array($this->validatorSchema['email'], new sfValidatorEmail(array(), array('invalid' => 'No es una dirección de email válida'))));
		$this->validatorSchema['password'] = new sfValidatorString(array('min_length' => 6), array('min_length' => 'El password debe tener por lo menos 6 caracteres.'));
		$this->validatorSchema['confirmar_password'] = new sfValidatorString(array('max_length' => 255));

		$this->validatorSchema->setPostValidator(new sfValidatorAnd(array(
			new sfValidatorSchemaCompare('password', sfValidatorSchemaCompare::EQUAL, 'confirmar_password', array(), array('invalid' => 'Los passwords no coinciden')),
			new DeshabilitarUsuarioAdministradorValidator(array('nombre' => 'nombre', 'habilitado' => 'habilitado', 'rol' => 'rol', 'club_id' => 'club_id'), array('invalid' => '')),
			$this->validatorSchema->getPostValidator()
		)));
		if ($this->getOption('embedded', null) != null) {
			unset($this['club_id'], $this['email']);
			$callback = sfContext::getInstance()->getRequest()->getParameter($this->getOption('embedded'));
			$callback = $callback[$this->getModelName()];
		} else {
			$callback = sfContext::getInstance()->getRequest()->getParameter($this->getName());
		}
		if(isset($callback['cambiar_password']))
		{
			$this->widgetSchema['cambiar_password'] = new sfWidgetFormInputHidden();
			$this->validatorSchema['cambiar_password'] = new sfValidatorPass();
		} else if (!$this->isNew()) {
			unset(
			$this['password'],
			$this['confirmar_password']
			);
			$this->widgetSchema['cambiar_password'] = new sfWidgetFormInput(array('type' => 'submit'));
		}

	}

}
